/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.playground.core.service;

import com.playground.core.entity.GameTitle;
import com.playground.core.entity.Invitation;
import com.playground.core.entity.Player;
import java.util.List;

/**
 *
 * @author Tiago Peres
 */
public interface InvitationService {
    /**
     * Assigns the guests answer to the given invitation.
     * 
     * @param invitation the invitation to be answered
     * @param guest the guest answering the invitation
     * @param answer the guests answer, yes (true) or no (false)
     * @return true if the invitation was successfully answered, false if the
     * invitation was not found
     */
    boolean answerInvitation(Invitation invitation, Player guest, boolean answer);
    
    /**
     * Creates an invitation from "host" to "guests", asking "guests" to play
     * "gameTitle".
     * 
     * @param host the invitation's creator
     * @param guests the invited players
     * @param gameTitle the gameTitle of the game to be played
     * @return the created invitation
     */
    Invitation createInvitation(Player host, List<Player> guests, GameTitle gameTitle);
    
    /**
     * Get the invitation created by the player "host".
     * A player can have only one invitation active at the same time.
     * 
     * @param host the invitation's host
     * @return the invitation or null if no invitation is found
     */
    Invitation getInvitation(Player host);
    
    /**
     * Removes the specified invitation if it exists.
     * 
     * @param invitation the injvitation to be removed
     * @return true if the invitation was successfully removed, false if the
     * invitation was not found
     */
    boolean removeInvitation(Invitation invitation);
    
    /**
     * Makes the invitation wait for a host confirmation.
     * This method should be called if not all guests accepted the invitation.
     * In this case, the invitation should wait for the host to answer if he
     * wants to enter the queue with just the players who accepted his invitation.
     * 
     * An invitation can only be set to "waitingForHostConfirmation" if its status
     * was "answered" or "answerTimeExpired". This method also sets the attribute
     * "waitingForHostSince" in the invitation.
     * 
     * If the invitation status wasn't "answered" nor "answerTimeExpired", or
     * if the invitation was not found, "false"is returned.
     * 
     * @param invitation the invitation to wait for host's confirmation
     * @return true if the invitation is successfully waiting, false if the
     * operartion was not successfull.
     */
    boolean waitForHostConfirmation(Invitation invitation);
}
